home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Lattice C v5.02 d4.adf / examples / setdate.c < prev    next >
C/C++ Source or Header  |  1988-11-07  |  1KB  |  83 lines

  1. #include "stdio.h"
  2. /*
  3. *    This is a sample program to set the date and time on the Amiga
  4. *    There is lots of room for improvement, but it makes a nice
  5. *    example of using the date and clock functions.
  6. */
  7.  
  8. static char *day_of_week[] = {    "Sun",
  9.                 "Mon",
  10.                 "Tue",
  11.                 "Wed",
  12.                 "Thu",
  13.                 "Fri",
  14.                 "Sat"
  15.                 };
  16. void main()
  17. {
  18.     char d[8],date[9],time[13],buf[41];
  19.     int a,b,c,e,f,g;
  20.     short i;
  21.  
  22.     getclk(d);
  23.     stpdate(date,3,&d[1]);
  24.     stptime(time,2,&d[4]);
  25.     i = d[0];
  26.     printf("Current date is %s  %s\n",day_of_week[i],date);
  27.     while(1)
  28.     {
  29.         printf("Enter new date (mm-dd-yy): ");
  30.         fgets(buf,40,stdin);
  31.         if(strlen(buf) < 2)
  32.         {
  33.             a = d[2];
  34.             b = d[3];
  35.             c = d[1] + 80;
  36.             break;
  37.         }
  38.         if ((sscanf(buf,"%d-%d-%d",&a,&b,&c) != 3) || (c < 80))
  39.         {
  40.             printf("Invalid date\n");
  41.             continue;
  42.         }
  43.         else break;
  44.     }
  45.     printf("Current time is: %s\n",time);
  46.     while(1)
  47.     {
  48.         printf("Enter new time (hh:mm:ss): ");
  49.         fgets(buf,40,stdin);
  50.         if(strlen(buf) < 2)
  51.         {
  52.             e = d[4];
  53.             f = d[5];
  54.             g = d[6];
  55.             break;
  56.         }
  57.         if((i = sscanf(buf,"%d:%d:%d",&e,&f,&g)) != 3)
  58.             {
  59.             if (i == 2) 
  60.                 {
  61.                 g = 0;
  62.                 break;
  63.                 }
  64.             else
  65.                 {
  66.                 printf("Invalid time\n");
  67.                 continue;
  68.                 }
  69.             }
  70.         else break;
  71.     }
  72.     d[0] = 0;
  73.     d[1] = c - 80;
  74.     d[2] = a;
  75.     d[3] = b;
  76.     d[4] = e;
  77.     d[5] = f;
  78.     d[6] = g;
  79.     d[7] = 0;
  80.     if(chgclk(d))    printf("Error setting clock...\n");
  81. }
  82.  
  83.